Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class DBHelper
    Public Shared Function GetSqlConnection() As SqlConnection
        Return GetSqlConnection(Define.ConnStr)
    End Function
    Private Shared Function GetConnectionString(ByVal IpAddress As String, ByVal DB As String, ByVal UserName As String, ByVal Password As String) As String
        Return "Data Source=" & IpAddress & ";Initial Catalog=" & DB & ";Persist Security Info=True;User ID=" & UserName & "; Password=" & Password & ""
    End Function
    Public Shared Function GetSqlConnection(ByVal connectString As String) As SqlConnection
        Try
            Dim Connection As New SqlConnection(connectString)
            'Connection.Open()
            Return Connection
        Catch Ex As System.Data.SqlClient.SqlException
        Finally
        End Try

        Return Nothing
    End Function
    Public Shared Function GetConnection() As SqlConnection
        Dim dbconnection As SqlConnection = GetSqlConnection()
        dbconnection.Open()
        Return dbconnection
    End Function
    Public Shared Function GetDataSetFromSQL(ByVal sql As String, ByVal lParamArray As SqlParameter()) As DataSet
        Dim _list As DataSet = Nothing
        Try
            Using con As SqlConnection = DBHelper.GetConnection()
                _list = SqlHelper.ExecuteDataset(con, CommandType.Text, sql, lParamArray)
            End Using
        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        Finally
        End Try
        Return _list
    End Function
    Public Shared Function ReadValue(ByVal dr As SqlDataReader) As ArrayList
        Dim strValue As New ArrayList
        Dim i As Integer = 0
        Try
            For i = 0 To dr.FieldCount - 1
                If Not IsDBNull(dr(i)) Then
                    strValue.Add(dr(i).ToString())
                Else
                    strValue.Add(Nothing)
                End If
            Next i
        Catch ex As Exception
            Throw New Exception(ex.Message.ToString, ex)
        Finally
        End Try
        Return strValue
    End Function
End Class
